﻿using System;
using System.Collections.Generic;

namespace Common.DataModels
{
    public class PageModel<T> where T:class
    {
        public int page { get;  set; } = 1;
        public int pageSize { get;  set; } = 20;
        public int dataCount { get;  set; } = 0;
        // 这样写 是只读属性 表示  读取的时候 会执行=>后面的代码  来获取pagecount
        public int pageCount => (int)Math.Ceiling(1.0 * dataCount / pageSize);
        public List<T> data { get;  set; }

        public PageModel()
        {
           
        }

        public PageModel(int page,int pageSize,int dataCount,List<T> data)
        {
            this.page = page;
            this.pageSize = pageSize;
            this.dataCount = dataCount;
            this.data = data;
        }

        public PageModel(PagingModel pagingModel, int dataCount, List<T> data)
        {
            this.pageSize = pagingModel.rows;
            this.page = pagingModel.page;
            this.dataCount = dataCount;
            this.data = data;
        }
    }
}
